package org.hcyspartnoc.demo.common.core.config;


import jakarta.annotation.Resource;
import org.hcyspartnoc.demo.common.core.configuration.UserConfiguration;
import org.hcyspartnoc.demo.common.core.interceptors.AuthInterceptor;
import org.hcyspartnoc.demo.common.core.interceptors.VisitInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ResourceConfig implements WebMvcConfigurer {
    @Resource
    private AuthInterceptor authInterceptor;
    @Resource
    private VisitInterceptor visitInterceptor;
    @Resource
    private UserConfiguration userConfiguration;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加访问拦截器
        registry.addInterceptor(visitInterceptor);
        //添加权限拦截器
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(userConfiguration.getIgnoreAuthUrl());
    }
}
